
package com.joysuch.wwyt.datadump.biz.query;

import cn.zlg.common.datadump.condition.QueryCondtionDef;
import cn.zlg.common.datadump.condition.QueryFieldCondition;
import cn.zlg.common.datadump.condition.QueryFieldConditionSet;
import cn.zlg.common.datadump.condition.SortFieldDef;
import com.joysuch.wwyt.bp.entity.dsl.QBpDepart;
import com.joysuch.wwyt.bp.entity.dsl.QBpJob;
import com.joysuch.wwyt.core.entity.dsl.QBaseLoginAccount;
import com.joysuch.wwyt.core.entity.dsl.QBaseUser;
import com.joysuch.wwyt.datadump.biz.condition.BaseUserDumpFindSubdepartIdConditionBuilder;
import com.joysuch.wwyt.util.ApplicationContextHolder;
import com.querydsl.core.types.Order;

import java.util.Arrays;
import java.util.List;

public class BaseUserDumpQueryBean implements QueryCondtionDef {

    @Override
    public List<QueryFieldConditionSet> getConditionSet() {
        return Arrays.asList(
                QueryFieldConditionSet.Builder().names("name").or(
                        new QueryFieldCondition("name", QBaseUser.baseUser, QBaseUser.baseUser.realName, QBaseUser.baseUser.id,
                                "contains"),
                        new QueryFieldCondition("name", QBaseUser.baseUser, QBaseUser.baseUser.code, QBaseUser.baseUser.id,
                                "contains")
                ).build(),
                QueryFieldConditionSet.Builder().names("state").or(
                        new QueryFieldCondition("state", QBaseUser.baseUser, QBaseUser.baseUser.state, QBaseUser.baseUser.id,
                                "ne"),
                        new QueryFieldCondition("state", QBaseUser.baseUser, QBaseUser.baseUser.state, QBaseUser.baseUser.id,
                                "isNull")
                ).build()
        );
    }

    @Override
    public QueryFieldCondition[] getAllConditionDef() {
        return new QueryFieldCondition[] {
                new QueryFieldCondition("ids", QBaseUser.baseUser, QBaseUser.baseUser.id, QBaseUser.baseUser.id, "in"),
                new QueryFieldCondition("sn", QBaseUser.baseUser, QBaseUser.baseUser.sn, QBaseUser.baseUser.id,
                        "contains"),

                new QueryFieldCondition("personTypeId", QBaseUser.baseUser, QBaseUser.baseUser.personTypeId,QBaseUser.baseUser.personTypeId,
                         "eq"),
                new QueryFieldCondition("departId", QBpDepart.bpDepart1, QBpDepart.bpDepart1.id, QBpDepart.bpDepart1.id,
                        QBaseUser.baseUser.departId, "eq"),
                new QueryFieldCondition("chiefId", QBaseUser.baseUser,
                        QBaseUser.baseUser.departId, ApplicationContextHolder.getBean(BaseUserDumpFindSubdepartIdConditionBuilder.class), "eq"),
                new QueryFieldCondition("jobId", QBpJob.bpJob, QBpJob.bpJob.id, QBpJob.bpJob.id, QBaseUser.baseUser.job,
                        "eq"),
                new QueryFieldCondition("account", QBaseLoginAccount.baseLoginAccount,
                        QBaseLoginAccount.baseLoginAccount.userName, QBaseLoginAccount.baseLoginAccount.baseUser.id,
                        QBaseUser.baseUser.id, "contains")
        };
    }

    @Override
    public SortFieldDef[] getAllSortFieldDef() {
        return new SortFieldDef[] {
                new SortFieldDef(QBaseUser.baseUser.id, "id", Order.DESC, true),
                new SortFieldDef(QBaseUser.baseUser.realName, "name", Order.ASC),
        };
    }
}
